#include "./TileMap.h"

namespace GameLogic {
namespace Level {

TileMap::TileMap( int width, int height, float tile_size ):
	width_( width ),
	height_( height ),
	tile_size_( tile_size ),
	tiles_( new Tile* [ width * height ] )
{
	int tile_array_size = width * height;
	for( int i = 0; i < tile_array_size; ++i )
		tiles_[ i ] = Tile::EMPTY;

}

TileMap::~TileMap() {
	int tile_array_size = width_ * height_;
	for( int i = 0; i < tile_array_size; ++i ) {
		if( tiles_[ i ] != Tile::EMPTY )
			delete tiles_[ i ];
	}
	delete [] tiles_;
}

void TileMap::insert( int x, int y, Tile* t ) {
	int array_offset = x + (y * width_);
	Tile* ct = tiles_[ array_offset ];
	if( (ct != 0) && (ct != Tile::EMPTY) ) {
		//TODO: jezeli dozwolone uzycie po fazie przygotowania levelu - skopiuj dane: obiekty, etc
		delete ct;
	}
	tiles_[ array_offset ] = t;
	t->onInsert( x, y, tile_size_ );
}

} //namespace Level
} //namespace GameLogic
